#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : micah
# @time    : 2023/12/2 17:39
# @function: the script is used to do something.
# @version :

import requests
from bs4 import BeautifulSoup as bs
from lxml import etree


# url
url = 'https://www.zhihu.com/expore'
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36'

}
response = requests.get(url, headers=headers).text
print(response)
# 提取数据
html_obj = etree.HTML(response)
result_list = html_obj.xpath("//div[@class='css-1g4zjtl']//a/text()")

for result in result_list:
    with open('zhihu_title.txt', 'a', encoding='utf-8') as f:
        print(result)
        f.write(result + '\n')

